package co.flante.entities;

import play.data.validation.Constraints.Required;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * <p>Title: Event entity</p>
 * <p>Description: A jpa entity use for persisting to the database and domain driven design.</p>
 * @author Mike Haas, Aaron Cook, Kyle Kolstad
 * @email michael.haas.@my.uwrf.edu, aaron.cook@my.uwrf.edu, kyle.kolstad@my.uwrf.edu
 * @date 11/25/2013
 */
@Entity
public class Event implements Serializable {
    @Id
    @Column(columnDefinition = "serial")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Basic
    private String description;

    @Basic
    @Required
    private Date created;

    @Basic
    private Date updated;

    public Event() {}

    public long getId() {
        return id;
    }

    public Event setId(long id) {
        this.id = id;

        return this;
    }

    public String getDescription() {
        return description;
    }

    public Event setDescription(String description) {
        this.description = description;

        return this;
    }

    /**
     * Automatically set a created field in the database
     */
    @PrePersist
    protected void onCreate() {
        this.created = updated = new Date();
    }

    /**
     * Automatically keep an updated field in the database.. up to date
     */
    @PreUpdate
    protected void onUpdate() {
        updated = new Date();
    }
}
